package com.example.androidexample.animation;

import android.view.animation.Animation;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.SeekBar;
import android.widget.TextView;

import androidx.annotation.IdRes;

import com.example.androidexample.R;

public class AnimationBasicParamsProvider implements CompoundButton.OnCheckedChangeListener, SeekBar.OnSeekBarChangeListener {

    private final AnimationActivity activity;
    private boolean afterFill = false;
    private long duration = 2000L;
    private int repeatMode = Animation.RESTART;
    private int repeatCount = 1;
    private CheckBox ckFillAfter;
    private TextView tvDuration;
    private SeekBar skbDuration;
    private CheckBox ckRepeatInfinite;
    private CheckBox ckRepeatMode;

    public AnimationBasicParamsProvider(AnimationActivity activity) {
        this.activity = activity;
        initView();
    }

    public boolean isAfterFill() {
        return afterFill;
    }

    public long getDuration() {
        return duration;
    }

    public int getRepeatMode() {
        return repeatMode;
    }

    public int getRepeatCount() {
        return repeatCount;
    }

    private void initView() {
        ckFillAfter = activity.findViewById(R.id.ck_fill_after);
        ckFillAfter.setOnCheckedChangeListener(this);

        tvDuration = activity.findViewById(R.id.tv_duration);
        skbDuration = activity.findViewById(R.id.skb_duration);
        skbDuration.setOnSeekBarChangeListener(this);

        ckRepeatInfinite = activity.findViewById(R.id.ck_repeat_infinite);
        ckRepeatInfinite.setOnCheckedChangeListener(this);

        ckRepeatMode = activity.findViewById(R.id.ck_repeat_mode);
        ckRepeatMode.setOnCheckedChangeListener(this);
    }


    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        @IdRes
        int cbId = buttonView.getId();
        switch (cbId) {
            case R.id.ck_fill_after: {
                afterFill = isChecked;
            } break;
            case R.id.ck_repeat_infinite: {
                repeatCount = isChecked?Animation.INFINITE:1;
            } break;
            case R.id.ck_repeat_mode: {
                repeatMode = isChecked?Animation.REVERSE:Animation.RESTART;
            } break;
        }
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        duration = progress;
        tvDuration.setText(duration+"");
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) { }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) { }
}
